#!/usr/bin/python2.5
#
# searchengine.py 
#
# Copyright 2012 Maxim Velikobratov (Jaropolk)
#
# Licensed under GNU GPL v3;
#
#     http://www.gnu.org/licenses/gpl.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import conf
from incl import *
from data_objects import *
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

class SearchEngine(webapp.RequestHandler):
  def post(self):
    s = self.request.get("q", default_value=" ")
    recipes = Recipes.all().filter("name =", s).fetch(10)

    params = {
      'SectionName': "Search " + s,
      'config': conf,
      #'cnt': recipes.count(),
      'ProjectLogo': "<a href='/'><div id='logo'>FoodExpert</div></a>",
      'usernickname': users.get_current_user(),
      'searchbar': search_bar(self),
      'userbar': user_bar(self),
      'row': recipes,
      'is_user_admin': users.is_current_user_admin(),
    }
    path = os.path.join(os.path.dirname(__file__), 'search-results.html')
    self.response.out.write(template.render(path, params))

def main():
  application = webapp.WSGIApplication(
    [
      ('/se/', SearchEngine),
    ], debug=True)
  run_wsgi_app(application)

if __name__ == "__main__":
  main()

